//
//  WDCallBackManager.m
//  WDPolymerizeSDK
//
//  Created by little People on 2023/6/13.
//

#import "WDCallBackManager.h"
#import "WDADManager.h"
#import "WDOrientationManager.h"
@implementation WDCallBackManager
static WDCallBackManager *_CallBackManager = nil;
+ (instancetype)shareCallBackManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _CallBackManager = [[self alloc] init];
        
    });
    return _CallBackManager;
}

- (void)adCallBackWithType:(CallBackType)type adSpace:(AdSpace)adSpace message:(NSString *)msg
{
    if (type == Close || type == Finish)
    {
        if (adSpace == reward || adSpace == inter)
        {
//            [[NSUserDefaults standardUserDefaults] setObject:@"2" forKey:@"WDOrientation"];
            [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"WDOrientation"];
            [[WDOrientationManager shareOrientationManager] adjustingScreenOrientation];
        }
    }
    if (type == ShowFail || type == Close || type == Finish || type == LoadFail)
    {
        [[WDADManager shareADManager] adCompleOrColeOrFaile];
    }
    switch (adSpace) {
        case reward:
        {
            if (type == Finish)
            {
                if ([WDCallBack shareCallBack].onRewardVideoFinish)
                {
                    [WDCallBack shareCallBack].onRewardVideoFinish(adSpace);
                }
            }
            else if (type == ShowFail)
            {
                if ([WDCallBack shareCallBack].onRewardVideoShowFail)
                {
                    [WDCallBack shareCallBack].onRewardVideoShowFail(msg,adSpace);
                }
            }
            else if (type == Close)
            {
                if ([WDCallBack shareCallBack].onRewardVideoClose)
                {
                    [WDCallBack shareCallBack].onRewardVideoClose(adSpace);
                }
            }
            else if (type == Show)
            {
                if ([WDCallBack shareCallBack].onRewardVideoShow)
                {
                    [WDCallBack shareCallBack].onRewardVideoShow(adSpace);
                }
            }
        }
            break;
        case inter:
        {
            if (type == Finish)
            {
                if ([WDCallBack shareCallBack].onInterstitialClose)
                {
                    [WDCallBack shareCallBack].onInterstitialClose(adSpace);
                }
            }
            else if (type == ShowFail)
            {
                if ([WDCallBack shareCallBack].onInterstitialShowFail)
                {
                    [WDCallBack shareCallBack].onInterstitialShowFail(msg,adSpace);
                }
            }
            else if (type == Show)
            {
                if ([WDCallBack shareCallBack].onInterstitialShow)
                {
                    [WDCallBack shareCallBack].onInterstitialShow(adSpace);
                }
            }
        }
            break;
        case banner:
        {
            if (type == Finish)
            {
                if ([WDCallBack shareCallBack].onBannerRemoved)
                {
                    [WDCallBack shareCallBack].onBannerRemoved(adSpace);
                }
            }
            else if (type == ShowFail)
            {
                if ([WDCallBack shareCallBack].onBannerShowFail)
                {
                    [WDCallBack shareCallBack].onBannerShowFail(msg,adSpace);
                }
            }
            else if (type == Show)
            {
                if ([WDCallBack shareCallBack].onBannerShow)
                {
                    [WDCallBack shareCallBack].onBannerShow(adSpace);
                }
            }
        }
            break;
        case card:
        {
            if (type == Finish)
            {
                if ([WDCallBack shareCallBack].onCardAdRemoved)
                {
                    [WDCallBack shareCallBack].onCardAdRemoved(adSpace);
                }
            }
            else if (type == ShowFail)
            {
                if ([WDCallBack shareCallBack].onCardAdShowFail)
                {
                    [WDCallBack shareCallBack].onCardAdShowFail(msg,adSpace);
                }
            }
            else if (type == Show)
            {
                if ([WDCallBack shareCallBack].onCardAdShow)
                {
                    [WDCallBack shareCallBack].onCardAdShow(adSpace);
                }
            }
        }
            break;
        default:
            break;
    }
}

@end
